/**
 * 系统设置权限设置添加管理员
 */
import './index.less'
import tem from './index.html'
import $_fn from '~plugins'
class resetadminCtrl {
  constructor($scope,$rootScope,http,$ui) {
      $scope.cancel = function () {
          $rootScope.$uiDirectiveModal.close() //关闭方法
      }
      //初始化对象
      $scope.resetAdmin={
      	id:$scope.id
      }
      //输入错误提示
	  	$scope.err=function(datas){
	  		$scope[datas]=true;
	  		setTimeout(function() {
	  			$scope[datas]=false;
	  			$scope.$apply()
	  		}, 1000);
	  	}
      $scope.tiJiao1=function(){
      		if(!$scope.resetAdmin.password || $scope.resetAdmin.password .length<6){
      			$ui.toast({
					text:'请填写密码',
					type:'warning',
					appendTo:'.resetAdmin'
				})
      			$scope.err('password')
      			return
      		}
      		if(!$scope.resetAdmin.againPassword || $scope.resetAdmin.againPassword!=$scope.resetAdmin.password){
      			$ui.toast({
					text:'两次密码不一致',
					type:'warning',
					appendTo:'.resetAdmin'
				})
      			$scope.err('againPassword')
      			return
      		}
      		http.post('resetAdminPassword.do',$scope.resetAdmin,function (data) {
				if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.resetAdmin'
					})
					$scope.cancel()
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.resetAdmin'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	        })
      		
      		
      } 
  }
}
resetadminCtrl.$inject = ['$scope','$rootScope','http','$ui']
module.exports = angular.module('directive.resetadmin', []).directive('resetadmin', function() {
    return {
        template: tem,
        replace:true,
        controller: resetadminCtrl,
        scope:{
        	id:"@"
        }
    }
}).name